/*
 * GTFSImporter.java
 * 
 * Created by demory on Jul 6, 2009, 3:28:39 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.core.transit.gtfs;

import java.io.File;
import org.fpdev.core.Scenario;
import org.fpdev.core.transit.Provider;
import org.fpdev.apps.rtemaster.RouteMaster;

/**
 *
 * @author demory
 */
public class GTFSImporter {

  private RouteMaster ac_;

  private String dir_;
  private Provider prov_;
  private Scenario scen_;

  private GTFSDatabase db_;

  // the tables;
  private GTFSCalendarDates calDates_;
  private GTFSRoutes routes_;
  private GTFSTrips trips_;
  private GTFSShapes shapes_;

  public GTFSImporter(RouteMaster ac) {
    ac_ = ac;
    dir_ = "/home/demory/gtfs/trimet/0609/google_transit/";


    ac_.getEngine().getRoutes().getProviders().newProvider("tm", "TriMet");
    ac_.getGUI().getRouteSelectionPanel().updateProviders();
    scen_ = ac_.getEngine().getScenarios().getBase();
    prov_ = ac_.getEngine().getRoutes().getProviders().getProvider("tm");
    
    db_ = new GTFSDatabase(ac_.getEngine().getDataPackage());
    //processRoutes();
    //processTrips();
    //processShapes();
  }

  public void setDirectory(String dir) {
    dir_ = dir;
  }

  public void initTables() {
    calDates_ = new GTFSCalendarDates(new File(dir_+"calendar_dates.txt"), this);
    routes_ = new GTFSRoutes(new File(dir_+"routes.txt"), this);
    trips_ = new GTFSTrips(new File(dir_+"trips.txt"), this);
    shapes_ = new GTFSShapes(new File(dir_+"shapes.txt"), this);
  }

  public GTFSDatabase getDB() {
    return db_;
  }

  public GTFSRoutes getRoutes() {
    return routes_;
  }

  public GTFSTrips getTrips() {
    return trips_;
  }

  public GTFSShapes getShapes() {
    return shapes_;
  }

  public void processCalendarDates() {
    calDates_.initCalendarDates(ac_.getRouteOps().getRoutes().getCalendarServices());
  }

  public void processRoutes() {
    //GTFSRoutes routes = new GTFSRoutes(new File(dir_+"routes.txt"));
    routes_.initRoutes(ac_.getEngine().getRoutes(), scen_, prov_);
    ac_.getGUI().getRouteSelectionPanel().updateRoutes();
  }

  public void processShapes() {
    shapes_.initShapes();
  }

  /*private void processTrips() {
    GTFSTrips trips = new GTFSTrips(new File(dir_+"trips.txt"));
    trips.initTrips();
  }

  private void processShapes() {
    GTFSShapes shapes = new GTFSShapes(new File(dir_+"shapes.txt"));
    shapes.initShapes();
  }*/
}
